{% extends "base.html" %}

{% block title %}报警规则设置{% endblock %}

{% block content %}
<div class="container-fluid">
    <div class="row mb-4">
        <div class="col">
            <div class="d-flex justify-content-between align-items-center">
                <h2>报警规则设置</h2>
                <a href="{{ url_for('alarm.add_rule') }}" class="btn btn-primary">
                    <i class="fas fa-plus me-1"></i>添加规则
                </a>
            </div>
        </div>
    </div>

    <div class="row">
        <div class="col">
            <div class="card">
                <div class="card-body">
                    <div class="table-responsive">
                        <table class="table">
                            <thead>
                                <tr>
                                    <th>监控点</th>
                                    <th>参数</th>
                                    <th>最小值</th>
                                    <th>最大值</th>
                                    <th>报警级别</th>
                                    <th>状态</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                {% for rule in rules %}
                                <tr>
                                    <td>{{ rule.point.name }}</td>
                                    <td>{{ rule.parameter }}</td>
                                    <td>{{ rule.min_value }}</td>
                                    <td>{{ rule.max_value }}</td>
                                    <td>
                                        <span class="badge bg-{{ 'warning' if rule.level == 'warning' else 'danger' }}">
                                            {{ '警告' if rule.level == 'warning' else '危险' }}
                                        </span>
                                    </td>
                                    <td>
                                        <span class="badge bg-{{ 'success' if rule.enabled else 'secondary' }}">
                                            {{ '启用' if rule.enabled else '禁用' }}
                                        </span>
                                    </td>
                                    <td>
                                        <form action="{{ url_for('alarm.toggle_rule', rule_id=rule.id) }}" method="POST" class="d-inline">
                                            <button type="submit" class="btn btn-{{ 'secondary' if rule.enabled else 'success' }} btn-sm">
                                                {{ '禁用' if rule.enabled else '启用' }}
                                            </button>
                                        </form>
                                    </td>
                                </tr>
                                {% else %}
                                <tr>
                                    <td colspan="7" class="text-center">暂无报警规则</td>
                                </tr>
                                {% endfor %}
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %} 